// 控制左侧展示的图形类型
if (!com) var com = {}
if (!com.logicpartners) com.logicpartners = {}

// designer:window.canvasDesigner
// canvas:document.getElementById('labelDesigner')
com.logicpartners.toolsWindow = function (designer, canvas) {
  this.canvas = canvas
  this.canvasElement = $(canvas)
  this.labelDesigner = designer
  this.boundingBox = null
  var self = this

  this.toolsViewContainer = $('#toolsViewContainer')

  // 添加标签以及样式名称
  this.buttonView = $('<div></div>').addClass('designerToolbarContent').appendTo(this.toolsViewContainer)

  // 先判断点击的是否是当前选中的左侧图例，
  this.setTool = function (controller) {
    // self.labelDesigner.newObjectController：当前选择的
    //controller:点击的
    if (self.labelDesigner.newObjectController == controller) {
      self.labelDesigner.setNewObject(null)
      controller.button.removeClass('designerToolbarButtonActive')
    } else {
      if (self.labelDesigner.newObjectController)
        self.labelDesigner.newObjectController.button.removeClass('designerToolbarButtonActive')
      self.labelDesigner.setNewObject(controller)
      if (controller) {
        controller.button.addClass('designerToolbarButtonActive')
        if (controller.activate) controller.activate(this)
      }
    }
  }

  // 添加左侧图例
  this.addTool = function (controller) {
    var self = this
    controller.button.on('click', { tool: controller }, function (event) {
      self.setTool(event.data.tool)
    })

    this.buttonView.append(controller.button)
  }
}
